<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台（PHP版）
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码，建议反馈是我们前进的动力
// | 开源版本可自由商用，可去除界面版权logo
// | gitee下载：https://gitee.com/likeshop_gitee/likeadmin
// | github下载：https://github.com/likeshop-github/likeadmin
// | 访问官网：https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------


namespace app\adminapi\controller\room;


use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\room\RoomApartmentUserLists;
use app\adminapi\logic\room\RoomApartmentUserLogic;
use app\adminapi\validate\room\RoomApartmentUserValidate;
use app\common\model\room\RoomApartment;


/**
 * 公寓用户关联控制器
 * Class RoomApartmentUserController
 * @package app\adminapi\controller\room
 */
class RoomApartmentUserController extends BaseAdminController {


    /**
     * @notes 获取公寓用户关联列表
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/02/26 16:32
     */
    public function lists() {
        set_time_limit(0);
        return $this->dataLists(new RoomApartmentUserLists());
    }

    /**
     * 打印查询-用户汇总
     */
    public function print_lists_user_stat() {
        return $this->success('', [
            "lists" => (new RoomApartmentUserLists())->print_stat_lists(),
            "keyword" => (new RoomApartment())->getPrintKeywordListUserStat(),
        ], 1, 1);
    }

    /**
     * 打印查询-用户-设备详情
     */
    public function print_lists_user_device() {
        return $this->success('', [
            "lists" => (new RoomApartmentUserLists())->print_lists(),
            "keyword" => (new RoomApartment())->getPrintKeywordListUserDevice(),
        ], 1, 1);
    }


    /**
     * 导出-住户汇总
     */
    public function export_lists_user_stat() {
        $room_lists = new RoomApartmentUserLists();
        if ($this->request->param("export") == 2) {
            $fields = [
                'user_name' => '住户名',
                'user_mobile' => '手机号',
                'all_d_total_fee' => '总电费',
                'all_s_total_fee' => '总水费',
                'date_time' => '时间',
            ];
            $room_lists->setExport('进修公寓汇总', $room_lists->print_stat_lists(), $fields);
        } else {
            $room_lists->setExport('进修公寓汇总', [], []);
        }
        return $this->dataLists($room_lists);
    }

    /**
     * 导出-住户-设备详情
     */
    public function export_lists_user_device() {
        $room_lists = new RoomApartmentUserLists();
        if ($this->request->param("export") == 2) {
            $fields = [
                'room_name' => '房间信息',
                'user_name' => '住户名',
                'user_mobile' => '手机号',

                'd_base_number' => '电表底数',
                'd_reading' => '电表读数',
                'd_use_total' => '用电度数',
                'd_price' => '电单价',
                'd_total_fee' => '总电费',

                's_base_number' => '水表底数',
                's_reading' => '水表读数',
                's_use_total' => '用水度数',
                's_price' => '水单价',
                's_total_fee' => '总水费',

                'lift_fee' => '电梯费',
                'second_pressure_fee' => '二次加压费',
//            'all_total_fee' => '总费用',
                'month_time' => '时间',
            ];
            $room_lists->setExport("进修公寓详细", $room_lists->print_lists(), $fields);
        } else {
            $room_lists->setExport('进修公寓详细', [], []);
        }
        return $this->dataLists($room_lists);
    }


    /**
     * @notes 添加公寓用户关联
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/02/26 16:32
     */
    public function add() {
        $params = (new RoomApartmentUserValidate())->post()->goCheck('add');
        $result = RoomApartmentUserLogic::add($params);
        if (true === $result) {
            return $this->success('添加成功', [], 1, 1);
        }
        return $this->fail(RoomApartmentUserLogic::getError());
    }


    /**
     * @notes 编辑公寓用户关联
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/02/26 16:32
     */
    public function edit() {
        $params = (new RoomApartmentUserValidate())->post()->goCheck('edit');
        $result = RoomApartmentUserLogic::edit($params);
        if (true === $result) {
            return $this->success('编辑成功', [], 1, 1);
        }
        return $this->fail(RoomApartmentUserLogic::getError());
    }


    /**
     * @notes 删除公寓用户关联
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/02/26 16:32
     */
    public function delete() {
        $params = (new RoomApartmentUserValidate())->post()->goCheck('delete');
        RoomApartmentUserLogic::delete($params);
        return $this->success('删除成功', [], 1, 1);
    }


    /**
     * @notes 获取公寓用户关联详情
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/02/26 16:32
     */
    public function detail() {
        $params = (new RoomApartmentUserValidate())->goCheck('detail');
        $result = RoomApartmentUserLogic::detail($params);
        return $this->data($result);
    }


}
